#!/usr/bin/env rc

fn escape {
  printf '\e[%sm' $1
}

fn block {
  printf '▄▀'
}

fn sep {
  printf '  '
}

fn chunk {
  escape $1
  block
  block
}

fn row {
  sep
  for (n) {
    chunk $n
    sep
  }
  
  echo
}

fn fg_row {
  escape 1
  row 30 31 32 33 34 35 36 37
  escape 22
  row 30 31 32 33 34 35 36 37
}

fn grid {
  escape 0
  fg_row
  for (n in 40 41 42 43 44 45 46 47) {
    escape $n
    fg_row
  }
  
  escape 0
}

cachefile=$home/.colorgrid.cache {
  if (! test -e $cachefile) {
    grid > $cachefile
  }
  
  cat $cachefile
}
